<!-- src/views/personnel/Onboarding.vue -->
<template>
  <div class="onboarding-container">
    <el-card>
      <div class="action-header">
        <h2>入职管理</h2>
        <div class="actions">
          <el-button type="primary" icon="el-icon-plus" @click="showCreateDialog">新建入职</el-button>
          <el-button type="success" icon="el-icon-upload" @click="handleImport">批量导入</el-button>
          <el-button icon="el-icon-download" @click="handleExport">导出数据</el-button>
        </div>
      </div>
    </el-card>

    <el-card class="mt-20">
      <el-table :data="onboardingList" style="width: 100%" height="600">
        <el-table-column prop="name" label="姓名" width="120" />
        <el-table-column prop="employeeId" label="员工编号" width="150" />
        <el-table-column prop="idNumber" label="身份证号" width="200" />
        <el-table-column prop="position" label="职位" width="180" />
        <el-table-column prop="department" label="部门" width="180" />
        <el-table-column prop="entryDate" label="入职日期" width="150" />
        <el-table-column prop="status" label="状态" width="120">
          <template #default="scope">
            <el-tag :type="scope.row.status === '已入职' ? 'success' : 'warning'">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
            v-model:current-page="currentPage"
            :page-size="pageSize"
            layout="total, prev, pager, next"
            :total="total"
            @current-change="handlePageChange"
        />
      </div>
    </el-card>

    <!-- 新建/编辑对话框 -->
    <el-dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
      <el-form :model="form" label-width="120px" ref="formRef">
        <el-tabs>
          <el-tab-pane label="基础信息">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="form.name" placeholder="请输入姓名" />
                </el-form-item>
                <el-form-item label="员工编号" prop="employeeId">
                  <el-input v-model="form.employeeId" placeholder="请输入员工编号" />
                </el-form-item>
                <el-form-item label="身份证类型" prop="idType">
                  <el-select v-model="form.idType" placeholder="请选择">
                    <el-option label="居民身份证" value="id_card" />
                    <el-option label="护照" value="passport" />
                    <el-option label="港澳通行证" value="hk_macau" />
                    <el-option label="其他" value="other" />
                  </el-select>
                </el-form-item>
                <el-form-item label="身份证号" prop="idNumber">
                  <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
                </el-form-item>
                <el-form-item label="性别" prop="gender">
                  <el-radio-group v-model="form.gender">
                    <el-radio label="male">男</el-radio>
                    <el-radio label="female">女</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生年月" prop="birthDate">
                  <el-date-picker
                      v-model="form.birthDate"
                      type="date"
                      placeholder="选择日期"
                      value-format="YYYY-MM-DD"
                  />
                </el-form-item>
                <el-form-item label="手机号" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入手机号" />
                </el-form-item>
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入邮箱" />
                </el-form-item>
                <el-form-item label="政治面貌" prop="politicalStatus">
                  <el-select v-model="form.politicalStatus" placeholder="请选择">
                    <el-option label="群众" value="people" />
                    <el-option label="共青团员" value="league" />
                    <el-option label="中共党员" value="party" />
                    <el-option label="其他" value="other" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="合同信息">
            <!-- 合同信息表单 -->
          </el-tab-pane>

          <el-tab-pane label="银行卡信息">
            <!-- 银行卡信息表单 -->
          </el-tab-pane>
        </el-tabs>
      </el-form>

      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

export default {
  setup() {
    const dialogVisible = ref(false)
    const dialogTitle = ref('新建入职')
    const formRef = ref(null)

    const form = reactive({
      name: '',
      employeeId: '',
      idType: 'id_card',
      idNumber: '',
      gender: 'male',
      birthDate: '',
      phone: '',
      email: '',
      politicalStatus: 'people'
    })

    const onboardingList = ref([
      {
        id: 1,
        name: '张三',
        employeeId: 'EMP001',
        idNumber: '310***********1234',
        position: '前端工程师',
        department: '技术部/前端组',
        entryDate: '2023-05-15',
        status: '已入职'
      },
      {
        id: 2,
        name: '李四',
        employeeId: 'EMP002',
        idNumber: '320***********5678',
        position: '后端工程师',
        department: '技术部/后端组',
        entryDate: '2023-05-20',
        status: '待入职'
      }
    ])

    const currentPage = ref(1)
    const pageSize = ref(10)
    const total = ref(2)

    const showCreateDialog = () => {
      dialogTitle.value = '新建入职'
      dialogVisible.value = true
    }

    const handleEdit = (row) => {
      dialogTitle.value = '编辑入职信息'
      Object.assign(form, row)
      dialogVisible.value = true
    }

    const handleView = (row) => {
      ElMessage.info(`查看 ${row.name} 的入职信息`)
    }

    const handleDelete = (row) => {
      ElMessage.success(`删除 ${row.name} 的入职记录`)
    }

    const submitForm = () => {
      ElMessage.success(`${dialogTitle.value}成功`)
      dialogVisible.value = false
    }

    const handleImport = () => {
      ElMessage.info('下载模板文件，填写后上传')
    }

    const handleExport = () => {
      ElMessage.success('数据导出成功')
    }

    const handlePageChange = (page) => {
      currentPage.value = page
    }

    return {
      dialogVisible,
      dialogTitle,
      formRef,
      form,
      onboardingList,
      currentPage,
      pageSize,
      total,
      showCreateDialog,
      handleEdit,
      handleView,
      handleDelete,
      submitForm,
      handleImport,
      handleExport,
      handlePageChange
    }
  }
}
</script>

<style scoped>
.onboarding-container {
  padding: 20px;
}

.action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.mt-20 {
  margin-top: 20px;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>